package org.iblink.gui.swing;

import javax.swing.SwingUtilities;

import org.apache.log4j.Logger;
import org.iblink.gui.swing.frames.IBlinkFrame;
import org.iblink.gui.swing.frames.LoadWindow;

/**
 * Main application class.
 * 
 * @author tpares
 *
 */
public class IBlink {

  /**
   * Class logger
   */
  private static Logger logger = Logger.getLogger(IBlink.class.getName());
  
  /**
   * Window to be displayed while application is loading
   */
  private static LoadWindow loadWindow = new LoadWindow();

  /**
   * Launches swing UI for ;Blink
   * 
   * @param args
   */
  public static void main(String[] args) {
    logger.debug("Launching application...");
    
    // display loading window
    SwingUtilities.invokeLater(new Runnable(){
      public void run(){
        synchronized(IBlink.loadWindow) {
          IBlink.loadWindow.setVisible(true);
        }
      }
    });
    
    // load application
    logger.debug("Calling initCategory");
    IBlinkContext.initCategories();
    
    // show main frame
    logger.debug("Calling swing frame");
    SwingUtilities.invokeLater(new Runnable(){
      public void run(){
        IBlinkFrame fenetre = new IBlinkFrame();
        
        synchronized(IBlink.loadWindow) {
          IBlink.loadWindow.setVisible(false);
        }
        
        fenetre.setVisible(true);
      }
    });
  }
}
